package com.FengChaoSystem.service.LoginService;

import com.FengChaoSystem.dao.LoginDao;
import com.FengChaoSystem.pojo.User;
import com.FengChaoSystem.service.LoginImpl;
import com.FengChaoSystem.untils.SqlSessionFactoryUtils;
import com.Mybatis.session.SqlSession;
import com.Mybatis.session.SqlSessionFactory;

public class LoginService implements LoginImpl {
    SqlSessionFactory sqlSessionFactory= SqlSessionFactoryUtils.getSqlSessionFactory();
    @Override
    public User login(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        LoginDao mapper = sqlSession.getMapper(LoginDao.class);
        User result = mapper.login(user);
        sqlSession.close();
        return result;
    }

    @Override
    public User selectPasswordByUserName(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        LoginDao mapper = sqlSession.getMapper(LoginDao.class);
        User result = mapper.selectPasswordByUserName(user);
        sqlSession.close();
        return result;
    }

    @Override
    public User selectIdByUserName(User target) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        LoginDao mapper = sqlSession.getMapper(LoginDao.class);
        User result = mapper.selectIdByUserName(target);
        sqlSession.close();
        return result;
    }
}
